//
// Created by bobin on 17-6-13.
//

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <glob.h>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <glog/logging.h>


inline std::vector<std::string> glob_vector(const std::string &pat) {
    using namespace std;
    glob_t glob_result;
    glob(pat.c_str(), GLOB_TILDE, NULL, &glob_result);
    vector<string> ret;
    for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
        ret.push_back(string(glob_result.gl_pathv[i]));
    }
    globfree(&glob_result);
    return ret;
}

bool LoadImgNameFromPath(const std::string &strPath, std::vector<std::string> &vstrImage) {
    vstrImage = glob_vector(strPath + "*.jpg");
}

void LoadImage(const std::string &fileName, cv::Mat &leftImg, cv::Mat &rightImg){
    cv::Mat whole_image = cv::imread(fileName, cv::IMREAD_GRAYSCALE);
    if(whole_image.empty())
        return;
    unsigned height = whole_image.rows/2;
    unsigned  width = whole_image.cols;
    cv::Rect left_roi = cv::Rect(0,height,width,height);
    cv::Rect right_roi = cv::Rect(0,0,width,height);

    leftImg = whole_image(left_roi).clone();
    rightImg = whole_image(right_roi).clone();
}


